package cn.sxt.sys.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

import cn.sxt.sys.domain.Permission;
import cn.sxt.sys.mapper.PermissionMapper;
import cn.sxt.sys.service.PermissionService;
import cn.sxt.sys.utils.DataGridView;
import cn.sxt.sys.vo.PermissionVo;

@Service
public class PermissionServiceImpl implements PermissionService{
	
	@Autowired
	private PermissionMapper permissionMapper;
	
	@Override
	public List<Permission> queryPermissionForList(PermissionVo permissionVo) {
		// TODO Auto-generated method stub
		return permissionMapper.queryAllPermission(permissionVo);
	}

	@Override
	public List<Permission> queryPermissionForList(PermissionVo permissionVo, Integer userid) {
		// 根据用户id查菜单
		return permissionMapper.queryPermissionByUserId(permissionVo.getType(),userid);
	}

	@Override
	public DataGridView queryAllPermission(PermissionVo permissionVo) {
		Page<Object> page = PageHelper.startPage(permissionVo.getPage(), permissionVo.getLimit());
		List<Permission> list = permissionMapper.queryAllPermission(permissionVo);
		return new DataGridView(page.getTotal(), list);
	}

	@Override
	public int addPermission(PermissionVo menuVo) {
		// TODO Auto-generated method stub
		return permissionMapper.insert(menuVo);
	}

	@Override
	public Permission queryPermissionById(Integer id) {
		// TODO Auto-generated method stub
		return permissionMapper.selectByPrimaryKey(id);
	}

	@Override
	public int updatePermission(PermissionVo permissionVo) {
		// TODO Auto-generated method stub
		return permissionMapper.updateByPrimaryKeySelective(permissionVo);
	}

	@Override
	public int deletePermissionById(PermissionVo permissionVo) {
		// TODO Auto-generated method stub
		return permissionMapper.deleteByPrimaryKey(permissionVo.getId());
	}

	@Override
	public List<Permission> queryPermissionByRoleIdForList(PermissionVo permissionVo, Integer roleid) {
		// TODO Auto-generated method stub
		return permissionMapper.queryPermissionByRoleId(permissionVo.getAvailable(),roleid);
	}

	@Override
	public List<Permission> queryPermissionByUserIdForList(String permissionTypePermission, Integer id) {
		// TODO Auto-generated method stub
		return permissionMapper.queryPermissionByUserId(permissionTypePermission, id);
	}

}
